<%--
  Created by IntelliJ IDEA.
  User: cui
  Date: 2021/9/16
  Time: 22:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"  isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/easyui/themes/default/easyui.css" type="text/css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/easyui/themes/icon.css" type="text/css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/plugins/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/plugins/easyui/jquery.easyui.min.js"></script>

</head>
<body>
<button type="button"  onclick="findAllByPage()" >分页查询</button>

<table id="listTable"></table>

<form id="listForm"  >
    <table>
        <tr>
            <td>用户名：</td>
            <td>
                <input class="easyui-textbox" id="username" name="username" required="required" data-options="required:true">
                <input class="easyui-datetimebox" name="birthday" data-options="required:true,showSeconds:false" value="3/4/2010 2:3" style="width:150px">
            </td>
        </tr>
        <tr>
            <td>年龄</td>
            <td>
                <input class="easyui-textbox" id="age" name="age" data-options="required:true">
            </td>
        </tr>
    </table>
    <input type="button" onclick="findAllByPage2()" value="查询">
</form>
<table id="listTable2"></table>

<%--             <table id="listTable3" class="easyui-datagrid"
                     striped="true"
                     url="${pageContext.request.contextPath}/sysLog/findAllByPage.do"
                     pagination="true"
                     pageList="[1,2,3]">
                 <thead>
                    <tr>
                         <th field="id" width="120" align="center" checkbox="true">编号</th>
                         <th field="visitTimeStr" width="120" align="center">收派名称</th>
                         <th field="username" width="120" align="center">最小重量</th>
                         <th field="ip" width="120" align="center">最大重量</th>
                         <th field="url" width="120" align="center">操作人</th>
                         <th field="executionTime" width="150" align="center">操作时间</th>
                     </tr>
                </thead>
         </table>--%>

<h2>上传csv文件</h2>
    <form enctype="multipart/form-data" method="post" action="${pageContext.request.contextPath}/sysLog/uploadFile.do" >
        姓名：<input type="text" name="username"><br>
        文件：<input type="file" name="multipartFile"><br>
        <input type="submit">
    </form>

<a href="${pageContext.request.contextPath}/sysLog/exportFile.do" >导出csv</a><br>
<br><br><br>



<h2>上传csv文件 java-csv解析</h2>
<form enctype="multipart/form-data" method="post" action="${pageContext.request.contextPath}/sysLog/uploadFileByJavaCSV.do" >
    姓名：<input type="text" name="username"><br>
    文件：<input type="file" name="multipartFile"><br>
    <input type="submit">
</form>
<a href="${pageContext.request.contextPath}/sysLog/exportFileByJavaCSV.do" >利用javaCSV导出csv</a><br>

<h2>上传csv文件  common-io.jar解析</h2>
<form enctype="multipart/form-data" method="post" action="${pageContext.request.contextPath}/sysLog/uploadFileByCommonIO.do" >
    姓名：<input type="text" name="username"><br>
    文件：<input type="file" name="multipartFile"><br>
    <input type="submit">
</form>
<a href="${pageContext.request.contextPath}/sysLog/exportFileByCommonIO.do" >利用common-io.jar 导出csv</a><br>

</body>
<script>
    $.fn.datetimebox.defaults.formatter = function(date){
        if (!date){return '';}
        var yyyy = date.getFullYear();
        var MM = formatN(date.getMonth()+1);
        var dd = formatN(date.getDate());

        var HH = formatN(date.getHours());
        var mm = formatN(date.getMinutes());
        var ss = formatN(date.getSeconds());
        return yyyy+'-'+MM+'-'+dd+' '+HH+':'+mm+':'+ss;

    }


    function formatN(value){
        return (value < 10 ? '0' : '') + value;
    }
    $.fn.datebox.defaults.formatter = function(date){
        if (!date){return '';}
        var yyyy = date.getFullYear();
        var MM = formatN(date.getMonth()+1);
        var dd = formatN(date.getDate());
        return yyyy+'-'+MM+'-'+dd;
    }



    function findAllByPage() {
        //错误，无法传递listForm的数据，也就是不会按照条件查询
        var formParam=$("#listForm").serialize();

        $('#listTable').datagrid({
            url:'${pageContext.request.contextPath}/sysLog/findAllByPage.do',
            queryParams:formParam,
            rownumber:true,
            pagination:true,
            columns:[[
                {field:'id',title:'ID',width:100},
                // {field:'visitTime',title:'访问时间',formatter:formatDate},
                {field:'visitTime',title:'访问时间'},
                {field:'username',title:'访问用户',width:100},
                {field:'ip',title:'访问IP',width:100},
                {field:'url',title:'资源URL'},
                {field:'executionTime',title:'执行时间',width:100},
                {field:'method',title:'访问方法',align:'right'},
            ]] ,
            onLoadSuccess:function(data){
                if(data.total>0){
                }
            }
        });
    }

    function formatDate(value,row,index){
        //方法一：
        var date = new Date(value);
        // var createtimeStr = date.toLocaleString(); //  2016/2/3 13:22:53
        // createtimeStr = createtimeStr.replace(new RegExp("/", 'g'),"-")// 2016-2-3 13:22:53
        // return createtimeStr;
    //方法二：
        var y = date.getFullYear();
        var m = dateFormat(date.getMonth() + 1);
        var d = dateFormat(date.getDate());
        let hours = dateFormat(date.getHours());
        let minute = dateFormat(date.getMinutes());
        let second = dateFormat(date.getSeconds());
        return y + '-' +m + '-' + d +' ' + hours + ':'+minute+':'+second;
    }

    // 不到2位就补0  1>01
    function dateFormat(date) {
        return date < 10 ? "0" + date : date;
    }
    function serializeFromToVO(form){
        var params = {};
        //自动序列化表单元素为JSON对象
        let fields = $(form).serializeArray();
        $.each(fields,function (i,field) {
            //设置查询参数
            params[field.name] = field.value;
        })
        return params;
    }

    function findAllByPage2() {
        $('#listTable2').datagrid({
            queryParams:serializeFromToVO("#listForm"),
            url:'${pageContext.request.contextPath}/sysLog/findAllByPage2.do',
            rownumber:true,
            pagination:true,
            columns:[[
                {field:'id',title:'ID',width:100},
                {field:'visitTimeStr',title:'访问时间',width:100},
                {field:'username',title:'访问用户',width:100},
                {field:'ip',title:'访问IP',width:100},
                {field:'url',title:'资源URL',width:100},
                {field:'executionTime',title:'执行时间',width:100},
                {field:'method',title:'访问方法',width:100,align:'right'},
            ]] ,
            remoteSort:false,
            onLoadSuccess:function(data){
                if(data.total>0){
                }
            }
        });
    }
</script>
</html>
